/**
 * 日期格式化
 * @param {String} 
 * @returns {str}
 */
 function timestampFormat(timestamp) {
    function zeroize(num) {
        return (String(num).length == 1 ? '0' : '') + num;
    }
    var curTimestamp = parseInt(new Date().getTime() / 1000); //当前时间戳
    var timestampDiff = curTimestamp - timestamp; // 参数时间戳与当前时间戳相差秒数
    var curDate = new Date(curTimestamp * 1000); // 当前时间日期对象
    var tmDate = new Date(timestamp * 1000); // 参数时间戳转换成的日期对象
    var Y = tmDate.getFullYear(),
        m = tmDate.getMonth() + 1,
        d = tmDate.getDate();
    var H = tmDate.getHours(),
        i = tmDate.getMinutes(),
        s = tmDate.getSeconds();
    if (timestampDiff < 60) { // 一分钟以内
        return "刚刚";
    } else if (timestampDiff < 3600) { // 一小时前之内
        return Math.floor(timestampDiff / 60) + "分钟前";
    } else if (curDate.getFullYear() == Y && curDate.getMonth() + 1 == m && curDate.getDate() == d) {
        return '今天' + zeroize(H) + ':' + zeroize(i);
    } else {
        var newDate = new Date((curTimestamp - 86400) * 1000); // 参数中的时间戳加一天转换成的日期对象
        if (newDate.getFullYear() == Y && newDate.getMonth() + 1 == m && newDate.getDate() == d) {
            return '昨天' + zeroize(H) + ':' + zeroize(i);
        } else if (curDate.getFullYear() == Y) {
            return zeroize(m) + '月' + zeroize(d) + '日 ' + zeroize(H) + ':' + zeroize(i);
        } else {
            return Y + '年' + zeroize(m) + '月' + zeroize(d) + '日 ' + zeroize(H) + ':' + zeroize(i);
        }
    }
}
/**
 * 快速获取时间
 * @param {String} str 
 * @returns String 
 */
function time(str) {
    var d = new Date()
    str = str.replaceAll('Y', d.getFullYear())
    str = str.replaceAll('m', d.getMonth() + 1)
    str = str.replaceAll('d', d.getDate())
    str = str.replaceAll('H', d.getHours())
    str = str.replaceAll('i', d.getMinutes())
    str = str.replaceAll('s', d.getSeconds())
    return str
}
/**
 * 获取随机颜色
 * @returns String
 */
function color() {
    var arr = '0123456789abcdef'.split('')
    var min = 0
    var max = arr.length - 1
    var one = arr[Math.floor(Math.random() * (max - min + 1) + min)]
    var two = arr[Math.floor(Math.random() * (max - min + 1) + min)]
    var three = arr[Math.floor(Math.random() * (max - min + 1) + min)]
    var four = arr[Math.floor(Math.random() * (max - min + 1) + min)]
    var five = arr[Math.floor(Math.random() * (max - min + 1) + min)]
    var six = arr[Math.floor(Math.random() * (max - min + 1) + min)]
    return '#' + one + two + three + four + five + six
    

}

/**
 * 判断浏览器内核
 * @returns String
 */
 function GetCurrentBrowser() {
    //取得浏览器的userAgent字符串
    var userAgent = navigator.userAgent.toLocaleLowerCase();
    var isChrome = userAgent.indexOf("chrome") > -1; //判断是否谷歌浏览器
    var isOpera = userAgent.indexOf("opera") > -1; //判断是否Opera浏览器
    var isIE = userAgent.match(/msie/) != null || userAgent.match(/trident/) != null;//userAgent.indexOf("compatible") > -1 && userAgent.indexOf("msie") > -1 && !isOpera; //判断是否IE浏览器
    var isFF = userAgent.indexOf("firefox") > -1; //判断是否Firefox浏览器
    var isSafari = userAgent.indexOf("safari") > -1; //判断是否Safari浏览器	
    if (isIE) {
        var IE5 = IE55 = IE6 = IE7 = IE8 = IE9 = IE11 = false;
        var fIEVersion = userAgent.match(/msie ([\d.]+)/) != null ? userAgent.match(/msie ([\d.]+)/)[1] : userAgent.match(/rv:([\d.]+)/)[1];
        IE55 = fIEVersion == 5.5;
        IE6 = fIEVersion == 6.0;
        IE7 = fIEVersion == 7.0;
        IE8 = fIEVersion == 8.0;
        IE9 = fIEVersion == 9.0;
        IE11 = fIEVersion == 11.0;
        if (IE55) {
            return "IE55";
        }
        if (IE6) {
            return "IE6";
        }
        if (IE7) {
            return "IE7";
        }
        if (IE8) {
            return "IE8";
        }
        if (IE9) {
            return "IE9";
        }
        if (IE11) {
            return "IE11";
        }
    }//isIE end
    if (isFF) {
        return "FF";
    }
    if (isOpera) {
        return "Opera";
    }
    if (isChrome) {
        return "Chrome";
    }
}

/**
 * 判断现在是PC还是移动true为PC端，false为手机端
 * @returns Bollean
 */
 function IsPC() {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["Android", "iPhone",
        "SymbianOS", "Windows Phone",
        "iPad", "iPod"];
    var flagPc = 'PC端';
    for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
            flagPc = '移动端';
            break;
        }
    }
    return flagPc;
}
var flagZt = IsPC();


/**
     * 判断是否是微信浏览器
     * @returns Boolean
     */
 function isWeiXin(){
         var ua = navigator.userAgent.toLowerCase()
         isWx = false
         if (ua.match(/MicroMessenger/i) == 'micromessenger') {
             //微信浏览器
             return true
         }
         else{
             return false
         }        
         
        }
        /**
 * 获取地址栏参数
 * @param {String} key 
 * @returns Boolean/String
 */

function getParam(key)
{
       //let query = window.location.search.substring(1);
       let query = window.location.href.split('?')[1]
       query = decodeURI(query)//decodeURI  用于解码 URI
       let vars = query.split("&");
       for (var i=0;i<vars.length;i++) 
       {
       		var tempArr = vars[i].split("=");
       		if(tempArr[0] == key) return tempArr[1]
       }
       return false;
}